using System;
using System.Collections.Generic;

namespace OffsetPath
{
    public class ForseLinea : ClassAf
    {
        public PuntoDueD a;
        public ClassAt b;

        public ForseLinea()
        {
            this.a = new PuntoDueD();
            this.b = new ClassAt();
        }

        public ForseLinea(ForseLinea classA0)
        {
            this.a = new PuntoDueD();
            this.b = new ClassAt();
            this.a.e(classA0.a);
            this.b.f(classA0.b);
        }

        public ForseLinea(PuntoDueD A_0, ClassAt A_1)
        {
            this.a = new PuntoDueD();
            this.b = new ClassAt();
            this.a.e(A_0);
            this.b.f(A_1);
        }

        public ForseLinea(PuntoDueD A_0, PuntoDueD A_1)
        {
            this.a = new PuntoDueD();
            this.b = new ClassAt();
            this.a.e(A_0);
            this.b.MethodA(A_0, A_1);
        }

        public ForseLinea(double A_0, double A_1, double A_2, double A_3)
        {
            this.a = new PuntoDueD();
            this.b = new ClassAt();
            this.a.MethodA(A_0, A_1);
            this.b.MethodA((double) (A_2 - A_0), (double) (A_3 - A_1));
        }

        public override ClassAf MethodA()
        {
            return new ForseLinea(this);
        }

        public void MethodA(double A_0)
        {
            this.b.MethodA(A_0);
        }

        public void MethodA(PuntoDueD A_0)
        {
            PuntoDueD puntoDueD = new PuntoDueD(this.a.X + this.b.a, this.a.Y + this.b.b);
            this.a.e(A_0);
            this.b.MethodA(PuntoDueD.MethodA(puntoDueD, this.a));
        }

        public bool MethodA(ForseLinea classA0, List<PuntoDueD> A_1)
        {
            PuntoDueD a = this.a;
            PuntoDueD x2 = this.i();
            PuntoDueD x3 = classA0.a;
            PuntoDueD x4 = classA0.i();
            double num = ((x4.X - x3.X) * (a.Y - x3.Y)) - ((x4.Y - x3.Y) * (a.X - x3.X));
            double num2 = ((x2.X - a.X) * (a.Y - x3.Y)) - ((x2.Y - a.Y) * (a.X - x3.X));
            double num3 = ((x4.Y - x3.Y) * (x2.X - a.X)) - ((x4.X - x3.X) * (x2.Y - a.Y));
            if (num3 == 0.0)
            {
                return false;
            }
            num /= num3;
            num2 /= num3;
            bool flag = ((num >= 0.0) && (num <= 1.0)) && (num2 >= 0.0);
            if (flag)
            {
                A_1.Add(new PuntoDueD(a.X + (num * (x2.X - a.X)), a.Y + (num * (x2.Y - a.Y))));
            }
            return flag;
        }

        public void MethodA(PuntoDueD A_0, ClassAt A_1)
        {
            this.a.e(A_0);
            this.b.f(A_1);
        }

        public void MethodA(PuntoDueD A_0, PuntoDueD A_1)
        {
            this.a.e(A_0);
            this.b.MethodA(A_0, A_1);
        }

        public double MethodA(ForseLinea classA0, PuntoDueD A_1, PuntoDueD A_2)
        {
            PuntoDueD puntoDueD = new PuntoDueD(classA0.i());
            ClassAt classAt = new ClassAt(this.a, classA0.a);
            ClassAt at2 = new ClassAt(this.a, puntoDueD);
            PuntoDueD x2 = new PuntoDueD(this.i());
            double num = classAt.MethodB(this.b);
            double num2 = at2.MethodB(this.b);
            if ((num <= 0.0) && (num2 <= 0.0))
            {
                A_1.e(this.a);
                return classA0.MethodD(this.a, A_2);
            }
            double num3 = this.g();
            num /= num3;
            num2 /= num3;
            if ((num >= num3) && (num2 >= num3))
            {
                A_1.e(x2);
                return classA0.MethodD(x2, A_2);
            }
            ClassAt at3 = new ClassAt(classA0.a, this.a);
            ClassAt at4 = new ClassAt(classA0.a, x2);
            double num4 = at3.MethodB(classA0.b);
            double num5 = at4.MethodB(classA0.b);
            if ((num4 <= 0.0) && (num5 <= 0.0))
            {
                A_2.e(classA0.a);
                return this.MethodD(classA0.a, A_1);
            }
            double num6 = classA0.g();
            num4 /= num6;
            num5 /= num6;
            if ((num4 >= num6) && (num5 >= num6))
            {
                A_2.e(puntoDueD);
                return this.MethodD(puntoDueD, A_1);
            }
            List<PuntoDueD> list = new List<PuntoDueD>();
            bool flag = true;
            bool flag2 = true;
            if (this.MethodA(classA0, list, ref flag, ref flag2, false))
            {
                A_2.e(list[0]);
                A_1.e(list[0]);
                return 0.0;
            }
            double num7 = 0.0;
            double num8 = 0.0;
            bool flag3 = false;
            PuntoDueD x3 = new PuntoDueD();
            PuntoDueD x4 = new PuntoDueD();
            if ((num >= 0.0) && (num <= num3))
            {
                double num9 = num / num3;
                x3.e(new PuntoDueD(this.a.X + (this.b.a * num9), this.a.Y + (this.b.b * num9)));
                num8 = classA0.a.MethodC(x3);
                flag3 = true;
                A_2.e(classA0.a);
                A_1.e(x3);
            }
            if ((num2 >= 0.0) && (num2 <= num3))
            {
                double num10 = num2 / num3;
                x3.e(new PuntoDueD(this.a.X + (this.b.a * num10), this.a.Y + (this.b.b * num10)));
                num7 = puntoDueD.MethodC(x3);
                if (!flag3 || (num7 < num8))
                {
                    A_2.e(puntoDueD);
                    A_1.e(x3);
                    num8 = num7;
                    flag3 = true;
                }
            }
            if ((num4 >= 0.0) && (num4 <= num6))
            {
                double num11 = num4 / num6;
                x4.e(new PuntoDueD(classA0.a.X + (classA0.b.a * num11), classA0.a.Y + (classA0.b.b * num11)));
                num7 = this.a.MethodC(x4);
                if (!flag3 || (num7 < num8))
                {
                    A_1.e(this.a);
                    A_2.e(x4);
                    num8 = num7;
                    flag3 = true;
                }
            }
            if ((num5 >= 0.0) && (num5 <= num6))
            {
                double num12 = num5 / num6;
                x4.e(new PuntoDueD(classA0.a.X + (classA0.b.a * num12), classA0.a.Y + (classA0.b.b * num12)));
                num7 = x2.MethodC(x4);
                if (flag3 && (num7 >= num8))
                {
                    return num8;
                }
                A_1.e(x2);
                A_2.e(x4);
                num8 = num7;
                flag3 = true;
            }
            return num8;
        }

        public bool MethodA(ForseLinea classA0, ref double A_1, PuntoDueD A_2, PuntoDueD A_3)
        {
            double b;
            double num2;
            double num3;
            double num4;
            PuntoDueD puntoDueD = new PuntoDueD(classA0.a.X + classA0.b.a, classA0.a.Y + classA0.b.b);
            PuntoDueD x2 = new PuntoDueD(this.a.X + this.b.a, this.a.Y + this.b.b);
            ClassAj classAj = new ClassAj(this.a.X, this.a.X);
            classAj.MethodB(x2.X);
            ClassAj aj2 = new ClassAj(classA0.a.X, classA0.a.X);
            aj2.MethodB(puntoDueD.X);
            ClassAj aj3 = new ClassAj();
            if (!classAj.MethodA(aj2, aj3))
            {
                return false;
            }
            if (this.b.a == 0.0)
            {
                b = this.a.Y;
                num2 = x2.Y;
            }
            else
            {
                b = this.d(aj3.b);
                num2 = this.d(aj3.a);
            }
            if (classA0.b.a == 0.0)
            {
                num3 = classA0.a.Y;
                num4 = puntoDueD.Y;
            }
            else
            {
                num3 = classA0.d(aj3.b);
                num4 = classA0.d(aj3.a);
            }
            double num5 = b - num3;
            double num6 = num2 - num4;
            if ((num5 > 0.0) && (num6 > 0.0))
            {
                num5 = Math.Abs(num5);
                num6 = Math.Abs(num6);
                if (num5 > num6)
                {
                    A_1 = num6;
                    A_2.X = aj3.a;
                    A_2.Y = num2;
                    A_3.X = aj3.a;
                    A_3.Y = num4;
                }
                else
                {
                    A_1 = num5;
                    A_2.X = aj3.b;
                    A_2.Y = b;
                    A_3.X = aj3.b;
                    A_3.Y = num3;
                }
                return true;
            }
            if ((num5 < 0.0) && (num6 < 0.0))
            {
                return false;
            }
            A_1 = 0.0;
            ClassAq classAq = new ClassAq();
            if (this.MethodB(classA0, classAq))
            {
                A_2 = classAq[0];
                A_3 = A_2;
            }
            return true;
        }

        public bool MethodA(ForseLinea classA0, List<PuntoDueD> A_1, ref bool A_2, ref bool A_3, bool A_4)
        {
            A_2 = false;
            A_3 = false;
            PuntoDueD a = this.a;
            PuntoDueD x2 = this.i();
            PuntoDueD x3 = classA0.a;
            PuntoDueD x4 = classA0.i();
            double num = ((x4.X - x3.X) * (a.Y - x3.Y)) - ((x4.Y - x3.Y) * (a.X - x3.X));
            double num2 = ((x2.X - a.X) * (a.Y - x3.Y)) - ((x2.Y - a.Y) * (a.X - x3.X));
            double num3 = ((x4.Y - x3.Y) * (x2.X - a.X)) - ((x4.X - x3.X) * (x2.Y - a.Y));
            if (num3 == 0.0)
            {
                return false;
            }
            num /= num3;
            num2 /= num3;
            A_2 = (num >= 0.0) && (num < 1.0);
            A_3 = (num2 >= 0.0) && (num2 < 1.0);
            bool flag = A_2 && ((bool) A_3);
            if (A_4 || flag)
            {
                A_1.Add(new PuntoDueD(a.X + (num * (x2.X - a.X)), a.Y + (num * (x2.Y - a.Y))));
            }
            return flag;
        }

        public bool MethodB(ForseLinea classA0)
        {
            PuntoDueD a = this.a;
            PuntoDueD x2 = this.i();
            PuntoDueD x3 = classA0.a;
            PuntoDueD x4 = classA0.i();
            double num = ((x4.X - x3.X) * (a.Y - x3.Y)) - ((x4.Y - x3.Y) * (a.X - x3.X));
            double num2 = ((x2.X - a.X) * (a.Y - x3.Y)) - ((x2.Y - a.Y) * (a.X - x3.X));
            double num3 = ((x4.Y - x3.Y) * (x2.X - a.X)) - ((x4.X - x3.X) * (x2.Y - a.Y));
            if (num3 == 0.0)
            {
                return false;
            }
            num /= num3;
            num2 /= num3;
            PuntoDueD x5 = new PuntoDueD(a.X + (num * (x2.X - a.X)), a.Y + (num * (x2.Y - a.Y)));
            if (num >= 0.5)
            {
                this.d(x5);
            }
            else
            {
                this.MethodA(x5);
            }
            if (num2 >= 0.5)
            {
                classA0.d(x5);
            }
            else
            {
                classA0.MethodA(x5);
            }
            return true;
        }

        public void MethodB(double A_0)
        {
            this.a.X -= ((this.b.a * A_0) - this.b.a) / 2.0;
            this.a.Y -= ((this.b.b * A_0) - this.b.b) / 2.0;
            this.b.d(A_0);
        }

        public bool MethodB(PuntoDueD A_0)
        {
            return (ClassAd.e(this.a, this.i(), A_0) < 0.0);
        }

        public bool MethodB(ForseLinea classA0, List<PuntoDueD> A_1)
        {
            bool flag = true;
            bool flag2 = true;
            return this.MethodA(classA0, A_1, ref flag, ref flag2, false);
        }

        public override bool MethodB(ClassAf A_0, List<PuntoDueD> A_1)
        {
            if (A_0 is ForseLinea)
            {
                return this.MethodB(A_0 as ForseLinea, A_1);
            }
            if (A_0 is ForseArcoClassQ)
            {
                ForseArcoClassQ forseArcoClassQ = A_0 as ForseArcoClassQ;
                return forseArcoClassQ.MethodB(this, A_1);
            }
            return false;
        }

        public double MethodB(PuntoDueD A_0, PuntoDueD A_1)
        {
            ClassAt classAt = new ClassAt(this.a, A_0);
            double num = classAt.MethodB(this.b) / ((this.b.a * this.b.a) + (this.b.b * this.b.b));
            A_1.MethodA((double) (this.a.X + (this.b.a * num)), (double) (this.a.Y + (this.b.b * num)));
            return A_0.MethodC(A_1);
        }

        public bool MethodB(ForseLinea classA0, ref double A_1, PuntoDueD A_2, PuntoDueD A_3)
        {
            double b;
            double num2;
            double num3;
            double num4;
            PuntoDueD puntoDueD = new PuntoDueD(classA0.a.X + classA0.b.a, classA0.a.Y + classA0.b.b);
            PuntoDueD x2 = new PuntoDueD(this.a.X + this.b.a, this.a.Y + this.b.b);
            ClassAj classAj = new ClassAj(this.a.X, this.a.X);
            classAj.MethodB(x2.X);
            ClassAj aj2 = new ClassAj(classA0.a.X, classA0.a.X);
            aj2.MethodB(puntoDueD.X);
            ClassAj aj3 = new ClassAj();
            if (!classAj.MethodA(aj2, aj3))
            {
                return false;
            }
            if (this.b.a == 0.0)
            {
                b = this.a.Y;
                num2 = x2.Y;
            }
            else
            {
                b = this.d(aj3.b);
                num2 = this.d(aj3.a);
            }
            if (classA0.b.a == 0.0)
            {
                num3 = classA0.a.Y;
                num4 = puntoDueD.Y;
            }
            else
            {
                num3 = classA0.d(aj3.b);
                num4 = classA0.d(aj3.a);
            }
            double num5 = num3 - b;
            double num6 = num4 - num2;
            if ((num5 * num6) > 0.0)
            {
                num5 = Math.Abs(num5);
                num6 = Math.Abs(num6);
                if (num5 > num6)
                {
                    A_1 = num6;
                    A_2.X = aj3.a;
                    A_2.Y = num2;
                    A_3.X = aj3.a;
                    A_3.Y = num4;
                }
                else
                {
                    A_1 = num5;
                    A_2.X = aj3.b;
                    A_2.Y = b;
                    A_3.X = aj3.b;
                    A_3.Y = num3;
                }
                return true;
            }
            A_1 = 0.0;
            ClassAq classAq = new ClassAq();
            if (this.MethodB(classA0, classAq))
            {
                A_2 = classAq[0];
                A_3 = A_2;
            }
            return true;
        }

        public void c(ForseLinea classA0)
        {
            this.a.e(classA0.a);
            this.b.f(classA0.b);
        }

        public PuntoDueD c(double A_0)
        {
            ClassAt classAt = new ClassAt(this.b);
            classAt.d(A_0);
            return new PuntoDueD(this.a.X + classAt.a, this.a.Y + classAt.b);
        }

        public override double MethodC(PuntoDueD A_0)
        {
            PuntoDueD puntoDueD = new PuntoDueD();
            return this.MethodD(A_0, puntoDueD);
        }

        public bool d(ForseLinea classA0)
        {
            bool flag = this.MethodB(classA0.a);
            bool flag2 = this.MethodB(classA0.i());
            return (flag ^ flag2);
        }

        public double d(double A_0)
        {
            if (this.b.a == 0.0)
            {
                return 0.0;
            }
            double num = this.b.b / this.b.a;
            return (((num * A_0) + this.a.Y) - (num * this.a.X));
        }

        public void d(PuntoDueD A_0)
        {
            this.b.MethodA(PuntoDueD.MethodA(A_0, this.a));
        }

        public override double MethodD(PuntoDueD A_0, PuntoDueD A_1)
        {
            ClassAt classAt = new ClassAt(this.a, A_0);
            double num = this.g();
            double num2 = classAt.MethodB(this.b);
            if (num2 < 0.0)
            {
                A_1.e(this.a);
                return A_0.MethodC(this.a);
            }
            num2 /= num;
            if (num2 < num)
            {
                double num3 = num2 / num;
                PuntoDueD puntoDueD = new PuntoDueD(this.a.X + (this.b.a * num3), this.a.Y + (this.b.b * num3));
                A_1.e(puntoDueD);
                return A_0.MethodC(puntoDueD);
            }
            A_1.e(this.i());
            return A_0.MethodC(this.i());
        }

        public double e(PuntoDueD A_0)
        {
            PuntoDueD puntoDueD = new PuntoDueD();
            return this.MethodB(A_0, puntoDueD);
        }

        public override double e(ClassAf A_0, PuntoDueD A_1, PuntoDueD A_2)
        {
            if (A_0 is ForseLinea)
            {
                return this.MethodA(A_0 as ForseLinea, A_1, A_2);
            }
            if (A_0 is ForseArcoClassQ)
            {
                ForseArcoClassQ forseArcoClassQ = A_0 as ForseArcoClassQ;
                return forseArcoClassQ.MethodA(this, A_1, A_2);
            }
            return 0.0;
        }

        public override void f(ClassAb A_0)
        {
            A_0.MethodB(this.a);
            A_0.e(this.i());
        }

        ~ForseLinea()
        {
        }

        public override double g()
        {
            return this.b.c();
        }

        public override PuntoDueD h()
        {
            return new PuntoDueD(this.a);
        }

        public override PuntoDueD i()
        {
            return new PuntoDueD(this.a.X + this.b.a, this.a.Y + this.b.b);
        }

        public override void j(List<PuntoDueD> A_0, List<ClassAf> A_1)
        {
            int count = A_0.Count;
            if (count == 0)
            {
                A_1.Add(new ForseLinea(this));
            }
            else
            {
                ClassAq classAq = new ClassAq();
                classAq.a(A_0);
                if (count > 1)
                {
                    classAq.c(this.a);
                }
                A_1.Add(new ForseLinea(this.a, classAq[0]));
                for (int i = 1; i < count; i++)
                {
                    A_1.Add(new ForseLinea(classAq[i - 1], classAq[i]));
                }
                A_1.Add(new ForseLinea(classAq[classAq.Count - 1], this.i()));
            }
        }

        public override void k(ForseLinea classA0, ClassAj A_1)
        {
            double num = this.a.MethodB(classA0);
            A_1.a = num;
            A_1.b = num;
            A_1.MethodB(this.i().MethodB(classA0));
        }

        public override void l(ClassAt A_0, ClassAj A_1)
        {
            double num = this.a.MethodA(A_0);
            A_1.a = num;
            A_1.b = num;
            A_1.MethodB(this.i().MethodA(A_0));
        }

        public override void m()
        {
            this.a.e(this.i());
            this.b.d();
        }

        public override void n(ClassAg A_0)
        {
            PuntoDueD puntoDueD = this.i();
            puntoDueD.n(A_0);
            this.a.n(A_0);
            this.d(puntoDueD);
        }

        public override void o(double A_0, PuntoDueD A_1)
        {
            PuntoDueD puntoDueD = new PuntoDueD(this.i());
            this.a.o(A_0, A_1);
            puntoDueD.o(A_0, A_1);
            this.d(puntoDueD);
        }

        public PuntoDueD p()
        {
            return new PuntoDueD(this.a.X + (this.b.a / 2.0), this.a.Y + (this.b.b / 2.0));
        }

        public override void p(ClassAt A_0)
        {
            this.a.p(A_0);
        }

        public override void q(ForseLinea classA0)
        {
            PuntoDueD puntoDueD = new PuntoDueD(this.i());
            this.a.q(classA0);
            puntoDueD.q(classA0);
            this.d(puntoDueD);
        }

        public override void r(PuntoDueD A_0)
        {
            PuntoDueD puntoDueD = new PuntoDueD(this.i());
            this.a.r(A_0);
            puntoDueD.r(A_0);
            this.d(puntoDueD);
        }

        public override void GetStartPoint(double A_0, PuntoDueD A_1)
        {
            this.a.GetStartPoint(A_0, A_1);
            this.b.MethodB(A_0);
        }
    }
}

